package com.db.patterns.proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {
    public static void main(String[] args) {
        Student xiaoBing = new Student("小兵");
        ShowLove showLove = (ShowLove) Proxy.newProxyInstance(xiaoBing.getClass().getClassLoader(),
                xiaoBing.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("代理收取一点好处费");
                        Object object = method.invoke(xiaoBing, args);
                        return object;
                    }
                });
        showLove.sendToys();
        showLove.sendFlowers();
    }
}
